<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  const arr = function (nums) {
    let res = []
    for (let i = 0, j = nums.length - 1; i <= j;) {
      const left = Math.abs(nums[i])
      const right = Math.abs(nums[j])
      if (right > left) {
        res.unshift(right * right)
        j--
      } else {
        res.unshift(left * left)
        i++
      }
    }
    return res
  }
  console.log(arr(nums = [-4, -1, 0, 3, 10]));
</script>

</html>